package com.shopping.cart.test

import com.shopping.cart.Item
import com.shopping.cart.ItemCategory
import com.shopping.cart.Image
import net.sf.ehcache.CacheManager
import net.sf.ehcache.config.Configuration
import net.sf.ehcache.config.FactoryConfiguration
import net.sf.ehcache.config.CacheConfiguration.CacheEventListenerFactoryConfiguration
import net.sf.ehcache.distribution.CacheManagerPeerListenerFactory
import net.sf.ehcache.config.ConfigurationFactory

class FixtureController {
    def createBasicItem = {
        ItemCategory category = ItemCategory.build(category:'home field')
        Image image = Image.build(name: 'title1', location:'flower1.jpg')
        Item.build(amount: 10.00 as BigDecimal, title: 'item1', categories: [category], images: [image])
        render 'k thanx'
    }

    def configureCache =  {

        //lets try to parse the configuration
        //modify the cacheManager
        Configuration config = ConfigurationFactory.parseConfiguration()

        //uncomment to allow for hostname to be changed
//        FactoryConfiguration peerProvider = config.getCacheManagerPeerListenerFactoryConfiguration()
//        peerProvider.setProperties('hostName=test,port=40001,remoteObjectPort=40002,socketTimeoutMillis=120000')

        CacheManager cacheManager = new CacheManager(config)
        render cacheManager.getCachePeerListener().getBoundCachePeers()
    }
}
